-- 隐报仇毒
local yinbaochoudu = fk.CreateSkill {
    name = "mcdh_yinbaochoudu",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

yinbaochoudu:addEffect(fk.AfterCardsMove,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if not player:hasSkill(self) then return false end
            for _, move in ipairs(data) do
                local to = move.to
                if move.to and move.to ~= player and move.toArea == Card.PlayerHand
                        and not to.dead and to.phase == Player.NotActive then
                    return true
                end
            end
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
            for _, move in ipairs(data) do
                local to = move.to
                if move.to and move.to ~= player and move.toArea == Card.PlayerHand and not move.to.dead and move.to.phase == Player.NotActive then
                    room:addPlayerMark(move.to, "@mcdh_yinbaochoudu", #move.moveInfo)
                end
            end
    end
})

yinbaochoudu:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if not player:hasSkill(self) then return false end
        return player == target and player.phase == Player.Start and table.find(
                        room.alive_players,
                        function(p)
                            return p:getMark("@mcdh_yinbaochoudu") >= p.maxHp
                        end
                        )
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(
                            room.alive_players,
                            function(p)
                                return p:getMark("@mcdh_yinbaochoudu") >= p.maxHp
                            end
                    )
        local players = room:askToChoosePlayers(
                    player,{
                        targets = targets,
                        min_num = 1,
                        max_num= #targets,
                        prompt =  "#mcdh_yinbaochoudu-choice",
                        skill_name=self.name
                    }
            )
        if #pids > 0 then
            self.cost_data = players
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        for _, p in ipairs(self.cost_data) do
            room:removePlayerMark(p, "@mcdh_yinbaochoudu", to.maxHp)
        end
        for _, p in ipairs(self.cost_data) do
            room:loseHp(p, 1, self.name)
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_yinbaochoudu"] = "隐报仇毒",
    [":mcdh_yinbaochoudu"] = "当一名其他角色在其回合外获得牌时，你令其获得等量枚「仇毒」标记。" ..
            "<br>准备阶段，你可以移去任意名角色各X枚「仇毒」（X为该角色体力上限），这些角色各失去1点体力。",
    ["#mcdh_yinbaochoudu-choice"] = "隐报仇毒:令任意名角色各移去体力上限枚「仇毒」并失去1点体力",
    ["@mcdh_yinbaochoudu"] = "仇毒",
}

return yinbaochoudu